package lab02.test23;

import java.util.*;


public class Test23 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你的生日，格式形如：2007-9-21:");

        Calendar calendar = Calendar.getInstance();
        //getInstance在单例模式(保证一个类仅有一个实例，并提供一个访问它的全局访问点)的类中常见，用来生成唯一的实例，getInstance往往是static的。

        String str = sc.nextLine();
        String year = str.substring(0, 4);
        //substring(start ,end ) 方法将返回一个包含从 start 到最后(不包含 end )的子字符串的字符串。
        String month = str.substring(5, 7);
        String day = str.substring(8);

        calendar.set(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(day));
                //parseInt是将字符串解析成int整数

        System.out.println("输出对应的是星期几:");
        int week = calendar.get(Calendar.DAY_OF_WEEK);
        switch (week) {
            case 1:
                System.out.println("MONDAY");
                break;
            case 2:
                System.out.println("TUESDAY");
                break;
            case 3:
                System.out.println("WEDNSSDAY");
                break;
            case 4:
                System.out.println("THESDAY");
                break;
            case 5:
                System.out.println("FIRDAY");
                break;
            case 6:
                System.out.println("SATUATFAY");
                break;
            default:
                System.out.println("SUNDAY");
                break;
        }
        Date date2 = new Date();
        calendar.set(2013, Integer.parseInt(month), Integer.parseInt(day));
        Date date1 = calendar.getTime();
        long countDay = (date1.getTime() - date2.getTime()) / (24 * 60 * 60 * 1000);
        if (countDay < 0) {
            calendar.set(2014, Integer.parseInt(month), Integer.parseInt(day));
            date1 = calendar.getTime();
            countDay = (date1.getTime() - date2.getTime()) / (24 * 60 * 60 * 1000);

        }
        System.out.println("距离你的生日还有" + countDay + "天。");
    }
}

